package com.lizemin.listener.controller;

import com.lizemin.listener.common.RespBean;
import com.lizemin.listener.listener.event.RegisterEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lzm
 * @date 2025/4/12 15:24
 * @description
 */
@RestController
@Slf4j
public class UserControllerV2 {

    @Autowired
    ApplicationEventPublisher eventPublisher;

    @GetMapping("/register/v2")
    public RespBean register(String username) {
        log.info("用户{}注册成功", username);

        // 发布用户注册成功的事件
        RegisterEvent event = new RegisterEvent(this, username);
        eventPublisher.publishEvent(event);
        return RespBean.success();
    }
}
